package com.bienvenue.main.ui.activity.personal;

import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import com.bienvenue.main.R;
import com.bienvenue.main.adapter.HomeFragmentPagerAdapter;
import com.bienvenue.main.base.BaseActivity;
import com.bienvenue.main.ui.fragment.personal.MainFragment;
import com.bienvenue.main.ui.fragment.personal.MeFragment;
import com.bienvenue.main.ui.fragment.personal.MessageFragment;
import com.bienvenue.main.weight.ViewPagerFixed;
import org.zackratos.ultimatebar.UltimateBar;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;

public class MainActivity extends BaseActivity implements ViewPager.OnPageChangeListener {
    @BindView(R.id.bn_bottom_bar)
    BottomNavigationView bnBottomBar;
    @BindView(R.id.contentViewPager)
    ViewPagerFixed contentViewPager;



    private MainFragment mainFragment;
    private List<Fragment> mFragmentList = new ArrayList<>(4);

    @Override
    protected void initData() {

//        ServiceModel.getServiceModel().setImg("storage/emulated/0/DCIM/Screenshots/Screenshot_2020-09-01-23-40-35-843_com.ss.android.ugc.aweme.jpg", new ResponseObserver<HttpBean>() {
//            @Override
//            public void onSuccess(HttpBean response) {
//                Log.e("TAG",response.getMessage());
//            }
//
//            @Override
//            public void onFail(String message) {
//                Log.e("TAG",message);
//
//            }
//        });


    }

    @Override
    protected void initView() {
        bnBottomBar.setItemIconTintList(null);
        //设置ViewPager的最大缓存页面
        contentViewPager.setOffscreenPageLimit(3);
        mainFragment = new MainFragment();
        mFragmentList.add(mainFragment);
        mFragmentList.add(new MessageFragment());
        mFragmentList.add(new MeFragment());
        contentViewPager.setAdapter(new HomeFragmentPagerAdapter(getSupportFragmentManager(), mFragmentList));
        contentViewPager.setOnPageChangeListener(this);

        bnBottomBar.setOnNavigationItemSelectedListener(item -> {
            switch (item.getItemId()) {
                case R.id.main:
                    contentViewPager.setCurrentItem(0);
                    break;
                case R.id.message:
                    contentViewPager.setCurrentItem(1);
                    setTitle("消息");
                    break;
                case R.id.me:
                    contentViewPager.setCurrentItem(2);
                    setTitle("我的");
                    break;
                default:
                    break;
            }
            return true;
        });
    }

    @Override
    protected int getLayoutId() {
        UltimateBar ultimateBar = new UltimateBar(this);
        ultimateBar.setColorBar(ContextCompat.getColor(this, R.color.color_4959FF));
        return R.layout.activity_main;
    }

    @Override
    public void onPageScrolled(int i, float v, int i1) {

    }

    @Override
    public void onPageSelected(int position) {
        switch (position) {
            case 0:
                bnBottomBar.setSelectedItemId(R.id.main);
                break;
            case 1:
                bnBottomBar.setSelectedItemId(R.id.message);
                break;
            case 2:
                bnBottomBar.setSelectedItemId(R.id.me);
                break;

            default:
                break;
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {
        if (state != ViewPager.SCROLL_STATE_IDLE) {
            //滚动过程中隐藏快速导航条
//            contactListFragment.showQuickIndexBar(false);
        } else {
//            contactListFragment.showQuickIndexBar(true);
        }
    }
}